<?php


namespace app\store\controller;

use EasyWeChat\Factory;

class Pay extends Controller
{
    public function notify()
    {

        $options = config("wechat_easy");

        $app =  Factory::officialAccount($options);

        $body = [
            'body' => '会查查-参赛报名费',
            'out_trade_no' =>123456789456,
            'total_fee' => 5 * 100,
            //'spbill_create_ip' => get_client_ip(), // 可选，如不传该参数，SDK 将会自动获取相应 IP 地址
            // 'notify_url' => 'https://www.huixx.cn/index/notify', // 支付结果通知网址，如果不设置则会使用配置里的默认地址
            'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
            'openid' => 'oJDVt5b3cxza-6Vs5cgVdLlFNhvo',
            //'sandbox' => true, // 设置为 false 或注释则关闭沙箱模式
        ];

        //$app->jssdk->buildConfig(array $APIs, $debug = false, $beta = false, $json = true, array $openTagList = []);

//        $app->jssdk->setUrl();

    }

    public function index()
    {
        $wechat_config = config("wechat_easy");

        $app = Factory::payment($wechat_config['payment']['default']);

        $result = $app->order->unify([
            'body' => '腾讯充值中心-QQ会员充值',
            'out_trade_no' => '20150806125346',
            'total_fee' => 88,
            //'spbill_create_ip' => '123.12.12.123', // 可选，如不传该参数，SDK 将会自动获取相应 IP 地址
            //'notify_url' => 'https://pay.weixin.qq.com/wxpay/pay.action', // 支付结果通知网址，如果不设置则会使用配置里的默认地址
            'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
            'openid' => 'oJDVt5b3cxza-6Vs5cgVdLlFNhvo',
        ]);

        $jssdk = $app->jssdk;

        $signPackage = $jssdk->bridgeConfig($result['prepay_id']);

        $signPackage = json_decode($signPackage,true);
//        var_dump($signPackage);
//        $app =  Factory::officialAccount($options);
//
//        $jssdk = $payment->jssdk;
//
//        $res = $app->jssdk->buildConfig(array('updateAppMessageShareData', 'updateTimelineShareData'), true);
        return $this->fetch('index',compact('signPackage'));
    }




}